{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'bpy'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-3b0a44bbcc0a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mbpy\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'bpy'"
     ]
    }
   ],
   "source": [
    "import bpy\n",
    "bpy.data.objects\n",
    "bpy.data.scenes\n",
    "bpy.data.objects[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'bpy' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-b7127bd6a135>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mbpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobjects\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'bpy' is not defined"
     ]
    }
   ],
   "source": [
    " bpy.data.objects[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'bpy' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-f90786ea104c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mbpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobjects\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'bpy' is not defined"
     ]
    }
   ],
   "source": [
    "bpy.data.objects[0].name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mesh = bpy.data.meshes.new(name=\"MyMesh\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bpy.context.object\n",
    "bpy.context.selected_objects\n",
    "bpy.context.visible_bones"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bpy.ops.mesh.flip_normals()\n",
    "\n",
    "bpy.ops.mesh.hide(unselected=False)\n",
    "\n",
    "bpy.ops.object.transform_apply()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import bpy\n",
    "\n",
    "\n",
    "def main(context):\n",
    "    for ob in context.scene.objects:\n",
    "        print(ob)\n",
    "\n",
    "\n",
    "class SimpleOperator(bpy.types.Operator):\n",
    "    \"\"\"Tooltip\"\"\"\n",
    "    bl_idname = \"object.simple_operator\"\n",
    "    bl_label = \"Simple Object Operator\"\n",
    "\n",
    "    @classmethod\n",
    "    def poll(cls, context):\n",
    "        return context.active_object is not None\n",
    "\n",
    "    def execute(self, context):\n",
    "        main(context)\n",
    "        return {'FINISHED'}\n",
    "\n",
    "\n",
    "def register():\n",
    "    bpy.utils.register_class(SimpleOperator)\n",
    "\n",
    "\n",
    "def unregister():\n",
    "    bpy.utils.unregister_class(SimpleOperator)\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    register()\n",
    "\n",
    "    # test call\n",
    "    bpy.ops.object.simple_operator()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import bpy\n",
    "\n",
    "\n",
    "class HelloWorldPanel(bpy.types.Panel):\n",
    "    \"\"\"Creates a Panel in the Object properties window\"\"\"\n",
    "    bl_label = \"Hello World Panel\"\n",
    "    bl_idname = \"OBJECT_PT_hello\"\n",
    "    bl_space_type = 'PROPERTIES'\n",
    "    bl_region_type = 'WINDOW'\n",
    "    bl_context = \"object\"\n",
    "\n",
    "    def draw(self, context):\n",
    "        layout = self.layout\n",
    "\n",
    "        obj = context.object\n",
    "\n",
    "        row = layout.row()\n",
    "        row.label(text=\"Hello world!\", icon='WORLD_DATA')\n",
    "\n",
    "        row = layout.row()\n",
    "        row.label(text=\"Active object is: \" + obj.name)\n",
    "        row = layout.row()\n",
    "        row.prop(obj, \"name\")\n",
    "\n",
    "        row = layout.row()\n",
    "        row.operator(\"mesh.primitive_cube_add\")\n",
    "\n",
    "\n",
    "def register():\n",
    "    bpy.utils.register_class(HelloWorldPanel)\n",
    "\n",
    "\n",
    "def unregister():\n",
    "    bpy.utils.unregister_class(HelloWorldPanel)\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    register()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "C.scene.objects"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import bpy\n",
    "bpy.data.objects[\"Cube\"].data.vertices[0].co.x += 1.0"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
